var start=0,page=1,showNumber=8,index=0,order='asc';
var contextPath;
var goodsList,source,origin,classifyname;
var shoppingcartTips = $('.shoppingcart__tips');
//加载更多
var isload = true,isTab=true;
$(function() {
		 contextPath = $("#contextPath").val();
		 var goodsbox= $(".goods-box-list");
		 goodsList = $("#content");
		 
		 var state = history.state;
		 var isInitLoad = false,oStart,top;
		 if(state != null){
				var key = state.key;
				if(key != null){
					source = state.source,order = state.order,index = state.index;
					oStart = state.start,start = state.start,page = state.page,top = state.top;
					classifyname = state.classifyname;
					if(order == 'desc'){
						var icon_price = $('.icon_price');
						icon_price.removeClass('price_down');
				        icon_price.attr("order",'desc');
					}else{
						var icon_price = $('.icon_price');
						icon_price.addClass('price_down');
						icon_price.attr("order",'asc');
					}
					isInitLoad = true;
				}
		}
		
		
		 
		if(isInitLoad){
			if(classifyname == undefined || $.trim(classifyname).length <=0 ){
				classifyname = "分类";
			}
			$("#classify").html(classifyname);
			if(index == 0){
				oHotGoodsBox(0, oStart, top);
			}else{
				oGoodsTabbox(0, oStart, top);
			}
			
		}else{
			var classid = $("#classid").val();
			if(classid.length>0){
				source = classid;
			}else{
				source=$("#source").val();
			}
			classifyname = $("#classifyname").val();
			if(classifyname == undefined || $.trim(classifyname).length <=0 ){
				classifyname = "分类";
			}
			$("#classify").html(classifyname);
			hotGoodsBox();
		}
		
		
		var list = new Tab('.list__tab', {
			  index: index,
			  onClick: function onClick(tab, _this) {
				  isTab = false;
				  var old = tab.old;
				  if(tab.index == 0){
					  index = 0;
					  paramInit();
					  hotGoodsBox();
					  sortIsShow(0);
				  }else if(tab.index == 1){
					  index = 1;
					  paramInit();
					  var icon_price = _this.querySelector('.icon_price');
				      var isActive = icon_price.classList.contains('price_down');
				      order = icon_price.getAttribute("order");
				      if (old === index) {
				        if (isActive) {
				          icon_price.classList.remove('price_down');
				          icon_price.setAttribute("order",'desc');
				        } else {
				          icon_price.classList.add('price_down');
				          icon_price.setAttribute("order",'asc');
				        };
				      }
				      order = icon_price.getAttribute("order");
				      goodsTabbox();
				      sortIsShow(1);
				  }else if(tab.index === 2){		  
					  setTimeout(function(){
						  tab.item[old].classList.add('tab_item_active');
						  _this.classList.remove('tab_item_active');
					  },0)
					  
					  getHtml();
				  }

			  }
			});		 
		 	

});

function paramInit(){
	start=0,page=1,isload=true;
	goodsList.empty();
	goodsList.html('<li class="popular__item placeholder" id="foo"></li><li class="popular__item placeholder"></li>');
	$(".lodingStyle").show();
}



function getHtml() {
	var HTML='';
	$.ajax({
		  url:"getClassChildrenList",
		  type:"post",
		  data:{"parentid":$("#source").val()},
		  dataType:"json",
		  success : function(data, textStatus) {
			  var state = data.result.state;
			  HTML += '<div class="sort_list"><ul>';
			  if(state == 1){
				  $.each(data.rClassificationList,function(i,v){
					  HTML += '<li class="sort_item" ><a parentid="'+v.classifyid+'" name="'+v.classifyname+'" href="javascript:void(0);"><i></i><span>'+ v.classifyname +'</span></a></li>';
				  });
			  }
			  HTML += '</ul></div>';
			  if(HTML!='<div class="sort_list"><ul></ul></div>'){
				  sort(HTML);
				  sortIsShow(2);
			  }
		   }
	  });
}
$(document).on('click','.sort_item a',function(){
	source = $(this).attr('parentid');
	var name = $(this).attr('name');
	$("#classify").html(name);
	paramInit();
	if(index == 0){
		hotGoodsBox();
	}else if(index == 1){
		goodsTabbox();
	}
	sortIsShow(1);
	
});

var timesr;
dropload.scroll(function(t,top){
	
	var top;
	clearTimeout(timesr);
	timesr = setTimeout(function(){
		top = document.body.scrollTop;
		var stateObj={key:Math.random(),start:start,page:page,top:top,index:index,source:source,order:order,classifyname:$("#classify").html()};
		window.history.replaceState(stateObj,"","");
	},500); 
	
	
		if(t<5&&isload&&isTab){
			$(".lodingStyle").show();
			isload = false;
			if(index == 0){
				hotGoodsBox();
			}else if(index == 1){
				goodsTabbox();
			}
			
		}
  });
function goodsTabbox(){
	var url,data;
	var search = $("#search").val();
	if(source =="goods"){
		url="goods/getGoodsList";
		data ={start:start,showNumber:showNumber,"params['order']":order};
	}else if(source == "search"){
		url="searchGoodsListByParmas";
		data ={start:start,showNumber:showNumber,"params['search']":search,"params['order']":order};
	}else if($.trim(search).length>0){
		url="getGoodsListByParmas";
		data ={start:start,showNumber:showNumber,search:search,orders:order,parentid:source};
	}else{
		url="goodsListByParentId";
		data ={start:start,showNumber:showNumber,parentid:source,orders:order};
	}
	goodsBox(url, data);
}

function oGoodsTabbox(oStart, oShowNumber, top){
	var url,data;
	var search = $("#search").val();
	if(source =="goods"){
		url="goods/getGoodsList";
		data ={start:oStart,showNumber:oShowNumber,"params['order']":order};
	}else if(source == "search"){
		url="searchGoodsListByParmas";
		data ={start:oStart,showNumber:oShowNumber,"params['search']":search,"params['order']":order};
	}else if($.trim(search).length>0){
		url="getGoodsListByParmas";
		data ={start:oStart,showNumber:oShowNumber,search:search,orders:order,parentid:source};
	}else{
		url="goodsListByParentId";
		data ={start:oStart,showNumber:oShowNumber,parentid:source,orders:order};
	}
	oGoodsBox(url, data, top);
}

function goodsBox(url,data){
	$.ajax({
		url:url,
		type:"post",
		async:true,
		data:data,
		dataType:"json",
		success : function(data, textStatus) {
			$(".lodingStyle").hide();
			var state = data.result.state;
			var html = "";
			if(state == 1){
				$.each(data.rGoodsList,function(i,v){
					if(v.is_points_buy == "01"){
						if(v.thumb == ""){
							if(v.change_price == 0){
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner"></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner">+</span><span class="dib vm commodity__live_price">'+ v.change_price + '<em class="n">元</em></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}else{
							if(v.change_price == 0){
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner"></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner">+</span><span class="dib vm commodity__live_price">'+ v.change_price + '<em class="n">元</em></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}
					}else{
						if(v.thumb == ""){
							html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><img src="'+contextPath+'/static/images/icon_default_02.jpg">';
							if(v.return_points>0){
								html+='<span class="layer_voucher">赠 <em class="n">'+v.return_points+'</em>兑换券</span></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html+='</span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}else{
							html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg">';
						    if(v.return_points>0){
						    	html+='<span class="layer_voucher">赠 <em class="n">'+v.return_points+'</em>兑换券</span></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
						    }else{
						    	html+='</span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
						    }
						}
					}
				});
				//goodsList.append(html);
				$("#foo").before(html);
				start=page*showNumber;
				page++;
				
				if(data.rGoodsList.length == showNumber){
					isload = true;	
				}
				var top = document.body.scrollTop;
				var stateObj={key:Math.random(),start:start,page:page,top:top,index:index,source:source,order:order,classifyname:$("#classify").html()};
				window.history.replaceState(stateObj,"","");
			}
			isTab = true;
			goodsIsNull();
		},
		error : function(XMLHttpRequest, textStatus, errorThrown){
			isTab = true;
			$(".lodingStyle").hide();
			layer.open({
			    content:textStatus,
			    time: 2
			});
		}
	});	
}


function oGoodsBox(url,data,top){
	$.ajax({
		url:url,
		type:"post",
		async:true,
		data:data,
		dataType:"json",
		success : function(data, textStatus) {
			$(".lodingStyle").hide();
			var state = data.result.state;
			var html = "";
			if(state == 1){
				$.each(data.rGoodsList,function(i,v){
					if(v.is_points_buy == "01"){
						if(v.thumb == ""){
							if(v.change_price == 0){
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner"></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner">+</span><span class="dib vm commodity__live_price">'+ v.change_price + '<em class="n">元</em></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}else{
							if(v.change_price == 0){
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner"></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner">+</span><span class="dib vm commodity__live_price">'+ v.change_price + '<em class="n">元</em></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}
					}else{
						if(v.thumb == ""){
							html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><img src="'+contextPath+'/static/images/icon_default_02.jpg">';
						    if(v.return_points>0){
						    html+='<span class="layer_voucher">赠 <em class="n">'+v.return_points+'</em>兑换券</span></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';	
						    }else{
						    html+='</span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
						    }
						}else{
							html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg">';
							if(v.return_points>0){
							html+='<span class="layer_voucher">赠 <em class="n">'+v.return_points+'</em>兑换券</span></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
							html+='</span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}
					}
				});
				//goodsList.append(html);
				$("#foo").before(html);
				document.body.scrollTop = top;
				
			}
			isTab = true;
			goodsIsNull();
		},
		error : function(XMLHttpRequest, textStatus, errorThrown){
			isTab = true;
			$(".lodingStyle").hide();
			layer.open({
			    content:textStatus,
			    time: 2
			});
		}
	});	
}

function goodsIsNull(){
	if(goodsList.find('.popular__item').length==2){
		shoppingcartTips.css('display','flex');
		$('#container').hide();
	}else{
		shoppingcartTips.hide();
		$('#container').show();
	}
}


function hotGoodsBox(){
	var url,data;
	var search = $("#search").val();
	if(source =="goods"){
		url="goods/getHotGoodsList";
		data ={start:start,showNumber:showNumber};
	}else if(source == "search"){
		url="searchHotGoodsListByParmas";
		data ={start:start,showNumber:showNumber,"params['search']":search};
	}else if($.trim(search).length>0){
		url="getHotGoodsListByParmas";
		data ={start:start,showNumber:showNumber,search:search,parentid:source};
	}else{
		url="hotGoodsListByParentId";
		data ={start:start,showNumber:showNumber,parentid:source};
	}
	
	goodsInit(url,data);
	
}

function oHotGoodsBox(oStart, oShowNumber, top){
	var url,data;
	var search = $("#search").val();
	if(source =="goods"){
		url="goods/getHotGoodsList";
		data ={start:oStart,showNumber:oShowNumber};
	}else if(source == "search"){
		url="searchHotGoodsListByParmas";
		data ={start:oStart,showNumber:oShowNumber,"params['search']":search};
	}else if($.trim(search).length>0){
		url="getHotGoodsListByParmas";
		data ={start:oStart,showNumber:oShowNumber,search:search,parentid:source};
	}else{
		url="hotGoodsListByParentId";
		data ={start:oStart,showNumber:oShowNumber,parentid:source};
	}
	
	oGoodsInit(url,data, top);
	
}

function goodsInit(url,data){
	$.ajax({
		url:url,
		type:"post",
		async:true,
		data:data,
		dataType:"json",
		success : function(data, textStatus) {
			$(".lodingStyle").hide();
			var state = data.result.state;
			var html = "";
			if(state == 1){
				$.each(data.rHotGoodsList,function(i,v){
					if(v.is_points_buy == "01"){
						if(v.thumb == ""){
							if(v.change_price == 0){
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner"></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner">+</span><span class="dib vm commodity__live_price">'+ v.change_price + '<em class="n">元</em></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}else{
							if(v.change_price == 0){
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner"></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner">+</span><span class="dib vm commodity__live_price">'+ v.change_price + '<em class="n">元</em></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}
					}else{
						if(v.thumb == ""){
							html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><img src="'+contextPath+'/static/images/icon_default_02.jpg">';
						    if(v.return_points>0){
						    html+='<span class="layer_voucher">赠 <em class="n">'+v.return_points+'</em>兑换券</span></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
						    }else{
						    html+='</span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>'; 	
						    }
						}else{
							html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg">';
							if(v.return_points>0){
							html+='<span class="layer_voucher">赠 <em class="n">'+v.return_points+'</em>兑换券</span></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';	
							}else{
							html+='</span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';	
							}
						}
					}
				});
				$('.loading_layer').hide();
				//goodsList.append(html);
				$("#foo").before(html);
				start=page*showNumber;
				page++;
				if(data.rHotGoodsList.length == showNumber){
					isload = true;	
				}
				var top = document.body.scrollTop;
				var stateObj={key:Math.random(),start:start,page:page,top:top,index:index,source:source,order:order,classifyname:$("#classify").html()};
				window.history.replaceState(stateObj,"","");
			}
			isTab = true;
			goodsIsNull();
		},
		error : function(XMLHttpRequest, textStatus, errorThrown){
			isTab = true;
			layer.open({
			    content:textStatus,
			    time: 2
			});
		}
	});	
}

function oGoodsInit(url,data, top){
	$.ajax({
		url:url,
		type:"post",
		async:true,
		data:data,
		dataType:"json",
		success : function(data, textStatus) {
			$(".lodingStyle").hide();
			var state = data.result.state;
			var html = "";
			if(state == 1){
				$.each(data.rHotGoodsList,function(i,v){
					if(v.is_points_buy == "01"){
						if(v.thumb == ""){
							if(v.change_price == 0){
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner"></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner">+</span><span class="dib vm commodity__live_price">'+ v.change_price + '<em class="n">元</em></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}else{
							if(v.change_price == 0){
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner"></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}else{
								html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><i class="vip_mark"></i><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg"></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__integral">' + v.change_points + '<em class="n">兑换券</em></span><span class="dib vm joiner">+</span><span class="dib vm commodity__live_price">'+ v.change_price + '<em class="n">元</em></span><span class="dib vm commodity__live_marketprice" style="display:none">市价1820</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';
							}
						}
					}else{
						if(v.thumb == ""){
							html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><img src="'+contextPath+'/static/images/icon_default_02.jpg">';
						    if(v.return_points>0){
						    html+='<span class="layer_voucher">赠 <em class="n">'+v.return_points+'</em>兑换券</span></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>'; 	
						    }else{
						    html+='</span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';	
						    }
						}else{
							html += '<li class="popular__item"><a href="'+ contextPath +'/goods/detailPage?goodsId=' + v.id + '"><span class="commodity__img"><img src="'+ v.thumb +'" width="100%" alt="" onerror="'+contextPath+'/static/images/icon_default_02.jpg">';
						    if(v.return_points>0){
						    html+='<span class="layer_voucher">赠 <em class="n">'+v.return_points+'</em>兑换券</span></span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';	
						    }else{
						    html+='</span><p class="commodity__txt">' + v.title + '</p></a><div class="commodity__live tj"><span class="dib vm commodity__live_price">&yen;'+ v.real_price + '</span><span class="dib vm commodity__live_marketprice">市价'+ v.price + '</span><span class="dib vm commodity__live_buy icon_car add_shopping_cart_btn"></span></div></div>';	
						    }
						}
					}
				});
				$('.loading_layer').hide();
				//goodsList.append(html);
				$("#foo").before(html);
				document.body.scrollTop = top;
			}
			isTab = true;
			goodsIsNull();
		},
		error : function(XMLHttpRequest, textStatus, errorThrown){
			isTab = true;
			layer.open({
			    content:textStatus,
			    time: 2
			});
		}
	});	
}
